<%@page contentType="text/html" pageEncoding="UTF-8" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<%@include file="_include.jsp" %>

<html>
<%--路径 /forum/section/{sectionId}/topic/{topicId}--%>
<head>
    <script src="${pageContext.request.contextPath}/resources/js/jquery-2.1.1.js"></script>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <title>${map.topic.title}</title>
</head>
<body>

<div>
    <%--用户信息 名称+
    主题+
    帖子数目+
    等级+
    头像+
    发消息+
    加好友+
    加关注--%>

    <%--帖子信息--%>
</div>
<h1>${map.topic.title}</h1>

<p>${map.topic.userName}</p>

<p>${map.topic.content}</p>


<%--已有回帖--%>
<c:forEach items="${map.replyList}" var="reply">
    <hr/>
    ${reply.userName}<br/>
    ${reply.lastModifiedTime}<br/>
    <c:if test="${reply.title != null && reply.title != ''}">
        ${reply.title}<br/>
    </c:if>
    ${reply.content}<br/>
</c:forEach>


<%--回帖--%>
<p id="showInfo"></p>
content:<br/>
<input id="content" type="text"><br/>
<button id="submit">回帖</button>
<script type="text/javascript">
    $('#submit').click(function () {
        console.log('提交文章'); //TODO
        var content = $('#content').val();
        if (!content) {
            $('#showInfo').text("内容不能为空");
            return;
        }

        var upData = {
            content: content,
            pTopicId: ${map.topic.topicId}+""
        }
        console.log(upData);
        $.ajax({
            type: 'POST',
            url: '/forum/section/${map.sectionId}/topic/articleReply',
            data: JSON.stringify(upData),
            contentType: "application/json",
            dataType: "json",
            success: function (data) {
                console.log(data);
                if (typeof data === 'string') {
                    data = JSON.parse(data);
                }

                if (data.isSucc === "true") {
                    window.location.reload();
                } else {
                    $("#showInfo").text(data.errMsg);
                }
            }, error: function (errMsg) {
                console.log(errMsg);
                $("#showInfo").text(errMsg);
            }
        });
    });
</script>
</body>
</html>
